package io.mft.commons.db;

import java.util.List;

import io.mft.commons.function.response.kv.KVMap;

/**
 * 	异步批量删除
 * @说明：TODO
 * @类型名称：AsyncBatchDeleteDbExecutor
 * @创建者: 胡常建  
 * @创建时间: 2021年9月15日 上午10:55:30
 * @修改者: 胡常建  
 * @修改时间: 2021年9月15日 上午10:55:30
 */
public class AsyncBatchDeleteDbExecutor<T> extends BaseAsyncBatchDbExecutor<T>{

	@SuppressWarnings("unchecked")
	public static <RT> AsyncBatchDeleteDbExecutor<RT> getInstance(Class<?>  owner,String aliasId,String dataSourceId,String tbName,int batchSize,int batchWorkerNumber) {
		String id=BaseAsyncBatchDbExecutor.class.getName()+"-"+aliasId+"-"+owner.getName()+"-"+dataSourceId+"-"+tbName+"-delete";
		if (map.containsKey(id)) {
			Object object= map.get(id);
			 AsyncBatchDeleteDbExecutor<RT> ab=( AsyncBatchDeleteDbExecutor<RT>)object;
			return ab;
		}
		synchronized (map) {
			if (!map.containsKey(id)) {
				try {
					AsyncBatchDeleteDbExecutor<RT> instancExecutor=new AsyncBatchDeleteDbExecutor<RT>(owner, aliasId, dataSourceId, tbName, batchSize, batchWorkerNumber);
					map.put(id, instancExecutor);
				} catch (Exception e) {
					logger.error("",e);
				}
			}
		}
		Object object= map.get(id);
		AsyncBatchDeleteDbExecutor<RT> ab=(AsyncBatchDeleteDbExecutor<RT>)object;
		return ab;
	}
	protected <AB extends BaseAsyncBatchDbExecutor<T>> AsyncBatchDeleteDbExecutor(Class<?> owner, String aliasId, String dataSourceId, String tbName,
			int batchSize, int batchWorkerNumber) {
		super(owner, aliasId, dataSourceId, tbName, batchSize, batchWorkerNumber);
	}

	private String[] where;
	public void where(String ...where) {
		this.where=where;
	}
	@Override
	protected int[] batch(String datasourceId, String tbName, List<KVMap> parameters) {
		int[] s=BatchExecuteUtil.executeDelete(datasourceId, tbName, where, parameters);
		return s;
	}

}
